// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
int main() {
int usb, ps2, both; cin >> usb >> ps2 >> both;
int m; cin >> m;
long long um[300000]; memset(um, 0, sizeof(um));
long long pm[300000]; memset(pm, 0, sizeof(pm));
int umNum = 0, pmNum = 0;
for (int i = 0; i < m; i++) {
long long p; string kind;
cin >> p >> kind;
if (kind == "USB") {
um[umNum++] = p;
} else {
pm[pmNum++] = p;
}
}
sort(um, um+umNum);
sort(pm, pm+pmNum);
int umInd = 0, pmInd = 0;
int count = 0;
long long cost = 0;
while (umInd < min(umNum, usb)) {
cost += um[umInd++];
count++;
}
while (pmInd < min(pmNum, ps2)) {
cost += pm[pmInd++];
count++;
}
while ((pmInd < pmNum || umInd < umNum) && both > 0) {
if (pmInd < pmNum && umInd < umNum) {
if (um[umInd] < pm[pmInd]) {
cost += um[umInd++];
} else {
cost += pm[pmInd++];
}
count++;
both--;
continue;
}
if (pmInd < pmNum) {
cost += pm[pmInd++];
} else {
cost += um[umInd++];
}
count++;
both--;
}
cout << count << " " << cost << endl;
}
1735B - Tea with Tangerines | 1735C - Phase Shift |
1321C - Remove Adjacent | 281B - Nearest Fraction |
1043A - Elections | 1598C - Delete Two Elements |
1400C - Binary String Reconstruction | 1734D - Slime Escape |
1499A - Domino on Windowsill | 991A - If at first you don't succeed |
1196C - Robot Breakout | 373A - Collecting Beats is Fun |
965A - Paper Airplanes | 863E - Turn Off The TV |
630E - A rectangle | 1104A - Splitting into digits |
19C - Deletion of Repeats | 1550B - Maximum Cost Deletion |
1693A - Directional Increase | 735D - Taxes |
989A - A Blend of Springtime | 339C - Xenia and Weights |
608A - Saitama Destroys Hotel | 1342C - Yet Another Counting Problem |
548A - Mike and Fax | 109A - Lucky Sum of Digits |
864C - Bus | 626B - Cards |
1221A - 2048 Game | 1374D - Zero Remainder Array |